package test;
import java.util.Scanner;
public class shudp {
    static int[] p;
    static int count;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int m = scan.nextInt();
        int n = scan.nextInt();
        p = new int[n*m+1];
        count=n*m;
        for(int i=1;i<n*m+1;i++){
            p[i]=i;
        }
        int k=scan.nextInt();
        for(int i=0;i<k;i++){
            int a=scan.nextInt();
            int b=scan.nextInt();
            connect(a,b);
        }
        System.out.println(count);
        scan.close();
    }
    public static void connect(int a,int b){
        int roota=find(a);
        int rootb=find(b);
        if(roota!=rootb){
            p[rootb]=roota;
            count--;
        }

    }
    public static int find(int a){
        if(p[a]!=a){
            p[a]=find(p[a]);
        }
        return p[a];
    }
}
